<template>
  <div>
    <a-modal
      :destroyOnClose="true"
      @cancel="cancel"
      v-model="visible"
      width="95%"
      :footer="false"
    >
      <a-tabs :activeKey="activeKey" @change="callback">
        <a-tab-pane :key="1" tab="1、方案名称">
          <CostScenarioName
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            :look="look"
            :modalFlag="modalFlag"
            :parentData="parentData"
          />
        </a-tab-pane>
        <a-tab-pane :key="2" tab="2、仓租设定" v-if="modalFlag != 'add'">
          <CostCharges
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="3" tab="3、清关费用" v-if="modalFlag != 'add'">
          <CostClearance
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :look="look"
            :parentData="parentData"
          />
        </a-tab-pane>
        <a-tab-pane :key="4" tab="4、入库卸货" v-if="modalFlag != 'add'">
          <CostDischarge
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :look="look"
            :modalFlag="modalFlag"
            :parentData="parentData"
          />
        </a-tab-pane>
        <a-tab-pane :key="5" tab="5、上架/清点" v-if="modalFlag != 'add'">
          <CostPutaway
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="6" tab="6、仓库增值" v-if="modalFlag != 'add'">
          <CostAppreciation
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="7" tab="7、订单处理" v-if="modalFlag != 'add'">
          <CostOrderHandle
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="8" tab="8、复合订单" v-if="modalFlag != 'add'">
          <CostOrderSymbol
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="9" tab="9、转运操作" v-if="modalFlag != 'add'">
          <CostTransferHandle
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="10" tab="10、退件接收" v-if="modalFlag != 'add'">
          <CostProductGet
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="11" tab="11、退件处理" v-if="modalFlag != 'add'">
          <CostProductHandle
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
        <a-tab-pane :key="12" tab="12、退件销毁" v-if="modalFlag != 'add'">
          <CostDestroy
            :activeKey="activeKey"
            @changeActiveKey="changeActiveKey($event)"
            @cancel="cancel"
            @addRules="addRules"
            :modalFlag="modalFlag"
            :parentData="parentData"
            :look="look"
          />
        </a-tab-pane>
      </a-tabs>
    </a-modal>
  </div>
</template>

<script>
import CostScenarioName from "./setCost/CostScenarioName";
import CostCharges from "./setCost/CostCharges";
import CostClearance from "./setCost/CostClearance";
import CostDischarge from "./setCost/CostDischarge";
import CostPutaway from "./setCost/CostPutaway";
import CostAppreciation from "./setCost/CostAppreciation";
import CostOrderHandle from "./setCost/CostOrderHandle";
import CostOrderSymbol from "./setCost/CostOrderSymbol";
import CostTransferHandle from "./setCost/CostTransferHandle";
import CostProductGet from "./setCost/CostProductGet";
import CostProductHandle from "./setCost/CostProductHandle";
import CostDestroy from "./setCost/CostDestroy";
export default {
  components: {
    CostScenarioName,
    CostCharges,
    CostClearance,
    CostDischarge,
    CostPutaway,
    CostAppreciation,
    CostOrderHandle,
    CostOrderSymbol,
    CostTransferHandle,
    CostProductGet,
    CostProductHandle,
    CostDestroy,
  },
  props: ["getTabList"],
  data() {
    return {
      parentData: {},
      modalFlag: "add",
      visible: false,
      activeKey: 1,
      look: null,
    };
  },
  mounted() {
    //新增
    this.$bus.$off("addScheme");
    this.$bus.$on("addScheme", (flag) => {
      this.visible = flag;
    });
    //编辑
    this.$bus.$off("editScheme");
    this.$bus.$on("editScheme", async (flag, record, modalFlag, look) => {
      this.parentData = record;
      this.modalFlag = modalFlag;
      if (look == "look") {
        this.look = "look";
      }
      this.visible = flag;
    });
  },
  methods: {
    handleCancel() {
      this.visible = false;
    },
    callback(key) {
      this.activeKey = key;
    },
    // 返回第一步
    addRules() {
      setTimeout(() => {
        this.activeKey = 1;
      }, 1000);
    },
    //子组件传过来的
    changeActiveKey(event) {
      if (this.activeKey == 1 && this.modalFlag == "add") {
        this.cancel();
        return false;
      }
      if (this.activeKey < 12) {
        this.activeKey = this.activeKey * 1 + event;
      } else {
        this.cancel();
      }
    },
    //关闭模态框
    cancel() {
      this.getTabList();
      this.visible = false;
      setTimeout(() => {
        this.$emit("delModal");
      }, 50);
    },
  },
};
</script>

<style lang="less" scoped></style>
